
/*
 * @Author: ljkt
 * @Version: 2.0
 * @Date: 2021-12-01 14:27:01
 * @LastEditors: ljkt
 * @LastEditTime: 2025-08-13 20:06:18
 * @Description:
 */
#include "./Common_Include.h"
Ram s_app_disp_t gAppDisp;
/**
 * @brief 初始化显示应用程序
 *
 * 该函数用于初始化显示应用程序。通过调用memset函数，将全局变量gAppDisp的所有字节设置为0，从而实现初始化。
 */
void App_Disp_Init(void)
{
    // 使用memset函数将gAppDisp结构体的所有字节设置为0，实现初始化
    memset(&gAppDisp, 0, sizeof(s_app_disp_t));
}

/**
 * @brief 初始化显示参数
 *
 * 该函数用于初始化显示参数。当命令发生变化时，重置子状态和超时时间。
 */
void DispParamInit(void)
{
    // 如果当前命令与上一次命令不同
    if (gAppDisp.LastCmd != gAppDisp.Cmd)
    {
        // 更新上一次命令为当前命令
        gAppDisp.LastCmd = gAppDisp.Cmd;
        // 重置子状态
        memset(&gAppDisp.Child, 0, sizeof(s_disp_child_t));
        // 设置超时时间为当前时间
        gAppDisp.Child.TimeOut = Drv_Get_Tick_u32();
        // 设置延迟时间为当前时间
        gAppDisp.Child.TimeDelay = Drv_Get_Tick_u32();
    }
}
/*
 * @description: 设置第一行88
 * @param {uchar} com1第一行第一个8
 * @param {uchar} com2第一行第二个8
 */
void One_shumaguan88_scan(uchar com1, uchar com2)
{
    if (com1)
    {
        if (com1 & LED_NUM_SA)
        {
            CF_DisplayBuf[LED_COM1 * CF_SEG_NUM + LED_SEG1] = huidu_PWM_255;
            CF_DisplayBuf[LED_COM1 * CF_SEG_NUM + LED_SEG8] = huidu_PWM_255;
        }

        if (com1 & LED_NUM_SB)
        {
            CF_DisplayBuf[LED_COM1 * CF_SEG_NUM + LED_SEG2] = huidu_PWM_255;
            CF_DisplayBuf[LED_COM1 * CF_SEG_NUM + LED_SEG9] = huidu_PWM_255;
        }

        if (com1 & LED_NUM_SC)
        {
            CF_DisplayBuf[LED_COM1 * CF_SEG_NUM + LED_SEG3] = huidu_PWM_255;
            CF_DisplayBuf[LED_COM1 * CF_SEG_NUM + LED_SEG10] = huidu_PWM_255;
        }

        if (com1 & LED_NUM_SD)
        {
            CF_DisplayBuf[LED_COM1 * CF_SEG_NUM + LED_SEG4] = huidu_PWM_255;
            CF_DisplayBuf[LED_COM1 * CF_SEG_NUM + LED_SEG11] = huidu_PWM_255;
        }
        if (com1 & LED_NUM_SE)
        {
            CF_DisplayBuf[LED_COM1 * CF_SEG_NUM + LED_SEG5] = huidu_PWM_255;
            CF_DisplayBuf[LED_COM1 * CF_SEG_NUM + LED_SEG12] = huidu_PWM_255;
        }
        if (com1 & LED_NUM_SF)
        {
            CF_DisplayBuf[LED_COM1 * CF_SEG_NUM + LED_SEG6] = huidu_PWM_255;
            CF_DisplayBuf[LED_COM1 * CF_SEG_NUM + LED_SEG13] = huidu_PWM_255;
        }
        if (com1 & LED_NUM_SG)
        {
            CF_DisplayBuf[LED_COM1 * CF_SEG_NUM + LED_SEG7] = huidu_PWM_255;
            CF_DisplayBuf[LED_COM1 * CF_SEG_NUM + LED_SEG14] = huidu_PWM_255;
        }
    }

    if (com2)
    {
        if (com2 & LED_NUM_SA)
        {
            CF_DisplayBuf[LED_COM2 * CF_SEG_NUM + LED_SEG1] = huidu_PWM_255;
            CF_DisplayBuf[LED_COM2 * CF_SEG_NUM + LED_SEG8] = huidu_PWM_255;
        }

        if (com2 & LED_NUM_SB)
        {
            CF_DisplayBuf[LED_COM2 * CF_SEG_NUM + LED_SEG2] = huidu_PWM_255;
            CF_DisplayBuf[LED_COM2 * CF_SEG_NUM + LED_SEG9] = huidu_PWM_255;
        }

        if (com2 & LED_NUM_SC)
        {
            CF_DisplayBuf[LED_COM2 * CF_SEG_NUM + LED_SEG3] = huidu_PWM_255;
            CF_DisplayBuf[LED_COM2 * CF_SEG_NUM + LED_SEG10] = huidu_PWM_255;
        }

        if (com2 & LED_NUM_SD)
        {
            CF_DisplayBuf[LED_COM2 * CF_SEG_NUM + LED_SEG4] = huidu_PWM_255;
            CF_DisplayBuf[LED_COM2 * CF_SEG_NUM + LED_SEG11] = huidu_PWM_255;
        }
        if (com2 & LED_NUM_SE)
        {
            CF_DisplayBuf[LED_COM2 * CF_SEG_NUM + LED_SEG5] = huidu_PWM_255;
            CF_DisplayBuf[LED_COM2 * CF_SEG_NUM + LED_SEG12] = huidu_PWM_255;
        }
        if (com2 & LED_NUM_SF)
        {
            CF_DisplayBuf[LED_COM2 * CF_SEG_NUM + LED_SEG6] = huidu_PWM_255;
            CF_DisplayBuf[LED_COM2 * CF_SEG_NUM + LED_SEG13] = huidu_PWM_255;
        }
        if (com2 & LED_NUM_SG)
        {
            CF_DisplayBuf[LED_COM2 * CF_SEG_NUM + LED_SEG7] = huidu_PWM_255;
            CF_DisplayBuf[LED_COM2 * CF_SEG_NUM + LED_SEG14] = huidu_PWM_255;
        }
    }
}
/*
 * @description: 设置第二行888
 * @param {uchar} com3 第二行第1个8
 * @param {uchar} com4 第二行第2个8
 * @param {uchar} com5 第二行第3个8
 * @return {*}
 */
void Two_shumaguan888_scan(uchar com3, uchar com4, uchar com5)
{
    if (com3)
    {
        if (com3 & LED_NUM_SA)
            CF_DisplayBuf[LED_COM3 * CF_SEG_NUM + LED_SEG1] = huidu_PWM_255;
        if (com3 & LED_NUM_SB)
            CF_DisplayBuf[LED_COM3 * CF_SEG_NUM + LED_SEG2] = huidu_PWM_255;
        if (com3 & LED_NUM_SC)
            CF_DisplayBuf[LED_COM3 * CF_SEG_NUM + LED_SEG3] = huidu_PWM_255;
        if (com3 & LED_NUM_SD)
            CF_DisplayBuf[LED_COM3 * CF_SEG_NUM + LED_SEG4] = huidu_PWM_255;
        if (com3 & LED_NUM_SE)
            CF_DisplayBuf[LED_COM3 * CF_SEG_NUM + LED_SEG5] = huidu_PWM_255;
        if (com3 & LED_NUM_SF)
            CF_DisplayBuf[LED_COM3 * CF_SEG_NUM + LED_SEG6] = huidu_PWM_255;
        if (com3 & LED_NUM_SG)
            CF_DisplayBuf[LED_COM3 * CF_SEG_NUM + LED_SEG7] = huidu_PWM_255;
    }

    if (com4)
    {
        if (com4 & LED_NUM_SA)
            CF_DisplayBuf[LED_COM4 * CF_SEG_NUM + LED_SEG1] = huidu_PWM_255;
        if (com4 & LED_NUM_SB)
            CF_DisplayBuf[LED_COM4 * CF_SEG_NUM + LED_SEG2] = huidu_PWM_255;
        if (com4 & LED_NUM_SC)
            CF_DisplayBuf[LED_COM4 * CF_SEG_NUM + LED_SEG3] = huidu_PWM_255;
        if (com4 & LED_NUM_SD)
            CF_DisplayBuf[LED_COM4 * CF_SEG_NUM + LED_SEG4] = huidu_PWM_255;
        if (com4 & LED_NUM_SE)
            CF_DisplayBuf[LED_COM4 * CF_SEG_NUM + LED_SEG5] = huidu_PWM_255;
        if (com4 & LED_NUM_SF)
            CF_DisplayBuf[LED_COM4 * CF_SEG_NUM + LED_SEG6] = huidu_PWM_255;
        if (com4 & LED_NUM_SG)
            CF_DisplayBuf[LED_COM4 * CF_SEG_NUM + LED_SEG7] = huidu_PWM_255;
    }

    if (com5)
    {
        if (com5 & LED_NUM_SA)
            CF_DisplayBuf[LED_COM5 * CF_SEG_NUM + LED_SEG1] = huidu_PWM_255;
        if (com5 & LED_NUM_SB)
            CF_DisplayBuf[LED_COM5 * CF_SEG_NUM + LED_SEG2] = huidu_PWM_255;
        if (com5 & LED_NUM_SC)
            CF_DisplayBuf[LED_COM5 * CF_SEG_NUM + LED_SEG3] = huidu_PWM_255;
        if (com5 & LED_NUM_SD)
            CF_DisplayBuf[LED_COM5 * CF_SEG_NUM + LED_SEG4] = huidu_PWM_255;
        if (com5 & LED_NUM_SE)
            CF_DisplayBuf[LED_COM5 * CF_SEG_NUM + LED_SEG5] = huidu_PWM_255;
        if (com5 & LED_NUM_SF)
            CF_DisplayBuf[LED_COM5 * CF_SEG_NUM + LED_SEG6] = huidu_PWM_255;
        if (com5 & LED_NUM_SG)
            CF_DisplayBuf[LED_COM5 * CF_SEG_NUM + LED_SEG7] = huidu_PWM_255;
    }
}

// 出水氛围灯控制
void LED_out_water_PWM_scan(uchar LED_pwm)
{
    static Ram uchar blue_pwm = 0;
    static Ram uchar red_pwm = 0;
    blue_pwm = (uchar)(LED_pwm & 0x0F); // 根据协议来低四位控制蓝灯灰度
    red_pwm = (uchar)(LED_pwm >> 4);    // 根据协议来低四位控制红灯灰度
    blue_pwm = (blue_pwm << 4);
    red_pwm = (red_pwm << 4);
    // 蓝灯PWM
    CF_DisplayBuf[LED_COM6 * CF_SEG_NUM + LED_SEG1] = blue_pwm;
    CF_DisplayBuf[LED_COM6 * CF_SEG_NUM + LED_SEG2] = blue_pwm;
    CF_DisplayBuf[LED_COM6 * CF_SEG_NUM + LED_SEG3] = blue_pwm;
    CF_DisplayBuf[LED_COM6 * CF_SEG_NUM + LED_SEG4] = blue_pwm;
    CF_DisplayBuf[LED_COM6 * CF_SEG_NUM + LED_SEG5] = blue_pwm;
    CF_DisplayBuf[LED_COM6 * CF_SEG_NUM + LED_SEG6] = blue_pwm;
    CF_DisplayBuf[LED_COM6 * CF_SEG_NUM + LED_SEG7] = blue_pwm;
    CF_DisplayBuf[LED_COM6 * CF_SEG_NUM + LED_SEG8] = blue_pwm;
    CF_DisplayBuf[LED_COM6 * CF_SEG_NUM + LED_SEG9] = blue_pwm;
    CF_DisplayBuf[LED_COM6 * CF_SEG_NUM + LED_SEG10] = blue_pwm;
    CF_DisplayBuf[LED_COM6 * CF_SEG_NUM + LED_SEG11] = blue_pwm;
    CF_DisplayBuf[LED_COM6 * CF_SEG_NUM + LED_SEG12] = blue_pwm;
    CF_DisplayBuf[LED_COM6 * CF_SEG_NUM + LED_SEG13] = blue_pwm;
    CF_DisplayBuf[LED_COM6 * CF_SEG_NUM + LED_SEG14] = blue_pwm;
    // 红灯PWM
    CF_DisplayBuf[LED_COM7 * CF_SEG_NUM + LED_SEG1] = red_pwm;
    CF_DisplayBuf[LED_COM7 * CF_SEG_NUM + LED_SEG2] = red_pwm;
    CF_DisplayBuf[LED_COM7 * CF_SEG_NUM + LED_SEG3] = red_pwm;
    CF_DisplayBuf[LED_COM7 * CF_SEG_NUM + LED_SEG4] = red_pwm;
    CF_DisplayBuf[LED_COM7 * CF_SEG_NUM + LED_SEG5] = red_pwm;
    CF_DisplayBuf[LED_COM7 * CF_SEG_NUM + LED_SEG6] = red_pwm;
    CF_DisplayBuf[LED_COM7 * CF_SEG_NUM + LED_SEG7] = red_pwm;
    CF_DisplayBuf[LED_COM7 * CF_SEG_NUM + LED_SEG8] = red_pwm;
    CF_DisplayBuf[LED_COM7 * CF_SEG_NUM + LED_SEG9] = red_pwm;
    CF_DisplayBuf[LED_COM7 * CF_SEG_NUM + LED_SEG10] = red_pwm;
    CF_DisplayBuf[LED_COM7 * CF_SEG_NUM + LED_SEG11] = red_pwm;
    CF_DisplayBuf[LED_COM7 * CF_SEG_NUM + LED_SEG12] = red_pwm;
    CF_DisplayBuf[LED_COM7 * CF_SEG_NUM + LED_SEG13] = red_pwm;
    CF_DisplayBuf[LED_COM7 * CF_SEG_NUM + LED_SEG14] = red_pwm;
}

// 状态灯控制
void LED_fun_status_scan(uchar fun_led)
{
    if (Read8Bit0(fun_led))
        LED_Fun_status_tds();
    if (Read8Bit1(fun_led))
        LED_Fun_status_chunshuishui();
    if (Read8Bit2(fun_led))
        LED_Fun_status_yuanshui();
    if (Read8Bit3(fun_led))
        LED_Fun_status_uv();
    if (Read8Bit4(fun_led))
        LED_Fun_status_tem();
    if (Read8Bit5(fun_led))
        LED_Fun_status_hotwater();
    if (Read8Bit6(fun_led))
        LED_Fun_status_zhishui();
    if (Read8Bit7(fun_led))
        LED_Fun_status_chongxi();
}

void LED_lvxin_scan(uchar lv_led)
{
    if (Read8Bit0(lv_led))
        LED_white_key_lvxin1();
    if (Read8Bit1(lv_led))
        LED_white_key_lvxin2();
    if (Read8Bit2(lv_led))
        LED_white_key_lvxin3();
    if (Read8Bit3(lv_led))
        LED_red_key_lvxin1();
    if (Read8Bit4(lv_led))
        LED_red_key_lvxin2();
    if (Read8Bit5(lv_led))
        LED_red_key_lvxin3();
    if (Read8Bit6(lv_led))
    {
    };
    if (Read8Bit7(lv_led))
    {
    };
}
void Pcba_Test(void)
{
    CONST unsigned char pwm_tab[] = {0xf0, 0x0f};
    CONST unsigned char smg888[] = {num0, num1, num2, num3, num4, num5, num6, num7, num8, num9, numa, numb, numc, numd, nume, numf};
    CONST unsigned char lv_tab[] = {0x07, 0xf8};
    static Ram unsigned char step = 0, old_key = 0;
    static Ram unsigned short tick_timeout = 0, tick_key = 0, tick_delay = 0;
    static Ram unsigned char _8 = 0, lv_cnt = 0x07, pwm_cnt = 0;
    if (Drv_Autoload_Ntick_u16(&tick_timeout, 60000ul))
    {
        step = 0xff;
    }
    switch (step)
    {
    case 0:
        if (Drv_Autoload_Ntick_u16(&tick_delay, 10000ul))
        {
            step = 0xff;
        }
        if (keys_flag != 0x03)
        {
            old_key = keys_flag;
            tick_key = Drv_Get_Tick_u16();
        }
        if (Drv_Autoload_Ntick_u16(&tick_key, 3000ul))
        {
            step = 1;
        }
        /* code */
        break;
    case 1:
        Dev_CF_DisplayClearBuf();
        if (Drv_Autoload_Ntick_u16(&tick_key, 1000ul))
        {
            _8++;
            _8 = _8 % 10;
            lv_cnt++;
            lv_cnt = lv_cnt % 2;
            pwm_cnt++;
            pwm_cnt = pwm_cnt % 2;
        }
        One_shumaguan88_scan(smg888[_8], smg888[_8]);
        Two_shumaguan888_scan(smg888[_8], smg888[_8], smg888[_8]);
        LED_out_water_PWM_scan(pwm_tab[pwm_cnt]);
        LED_fun_status_scan(0xff);
        LED_lvxin_scan(lv_tab[lv_cnt]); //
        if ((keys_flag) && (0 == old_key))
        {
            DEV_BUZ_SET_CMD(1, 500, 500);
        }
        old_key = keys_flag;
        break;
    default:
        break;
    }
}
void App_Disp_Scan(void)
{
    static Ram unsigned char tick = 0;
    // static uchar test_key=0;
    // ================================状态改变时，子状态归零===============================
    // DispParamInit();
    if (Drv_Autoload_Ntick_u8(&tick, 50ul))
    {
        Dev_CF_DisplayClearBuf();
        //   memset(&gAPP_rx_buf, 0, sizeof(uart_packet_t));
        //   gAPP_rx_buf.Dig8one_1=0xFF;
        //   gAPP_rx_buf.Dig8one_2=0xFF;
        //   gAPP_rx_buf.Dig8two_1=0xFF;
        //   gAPP_rx_buf.Dig8two_2=0xFF;
        //   gAPP_rx_buf.Dig8two_3=0xFF;
        //   gAPP_rx_buf.Huidu_pwm=0x0F;
        //   gAPP_rx_buf.Status_led=0xFF;
        //   gAPP_rx_buf.LV_led=0x07;

        One_shumaguan88_scan(gAPP_rx_buf.Dig8one_1, gAPP_rx_buf.Dig8one_2);
        Two_shumaguan888_scan(gAPP_rx_buf.Dig8two_1, gAPP_rx_buf.Dig8two_2, gAPP_rx_buf.Dig8two_3);
        LED_out_water_PWM_scan(gAPP_rx_buf.Huidu_pwm);
        LED_fun_status_scan(gAPP_rx_buf.Status_led);
        LED_lvxin_scan(gAPP_rx_buf.LV_led); //
        Pcba_Test();
    }
}
